#coding:utf-8
import time

from constants.url_58 import *
from util.common_util import print_line
from week1_homework.get_58 import get_page, get_zhuanzhuan_data
from util.mongodb_client import set_mongodb_connect

'''
根据分类爬取商品链接
'''

def get_item_link(index_url, category, page_num=10, seller=0):
    print_line("get_item_link")
    print("get_item_link, index_url:{}, category:{}, page_num:{}, seller:{}"
          .format(index_url, category, page_num, seller))

    break_count = 0
    for pageNum in range(1, page_num):
        page_url = '{}{}{}/pn{}/'.format(index_url, category, str(seller), str(pageNum))


        time.sleep(1)
        print("page_url:{}".format(page_url))
        datas = get_page(page_url, headers)

        if datas is -1:
            print('get_item_link end, category:{} pageNum:{}'.format(category, pageNum))
            return False

        if len(datas) == 0:
            break_count += 1;

        if break_count >= 5:
            print('get_item_link end, category:{} pageNum:{}'.format(category, pageNum))
            return False






